package org.erp.spu.controller;

import org.erp.common.domain.Result;
import org.erp.spu.entity.dto.SpuTemplateReleaseDto;
import org.erp.spu.entity.vo.SpuTemplateReleaseVo;
import org.erp.spu.service.SpuTemplateReleaseService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;

/**
 * 发布模板信息表(SpuTemplateRelease)控制层
 *
 * @author dingding
 * @since 2025-11-06 15:11:43
 */
@RequestMapping("/templateRelease")
@RestController
public class SpuTemplateReleaseController {

    @Resource
    private SpuTemplateReleaseService spuTemplateReleaseService;

    /**
     * 通过modelId获取发布项列表
     * @param modelId
     */
    @GetMapping("/getByModelId")
    public Result<SpuTemplateReleaseVo> getByModelId(@NotNull(message = "模板ID不能为空") Long modelId) {
        SpuTemplateReleaseVo spuTemplateReleaseVo = spuTemplateReleaseService.getByModelId(modelId);
        return Result.success(spuTemplateReleaseVo);
    }

    /**
     * 通过模板id获取发布项列表
     * @param templateId
     */
    @GetMapping("/getByTemplateId")
    public Result<SpuTemplateReleaseVo> getListByTemplateId(@NotNull(message = "模板ID不能为空") Long templateId) {
        SpuTemplateReleaseVo spuTemplateReleaseVo = spuTemplateReleaseService.getByTemplateId(templateId);
        return Result.success(spuTemplateReleaseVo);
    }
    /**
     * 编辑模版发布项信息
     * @param spuTemplateReleaseDto
     * @return
     */
    @PostMapping("/edit")
    public Result<Boolean> editSpuTemplateRelease(@RequestBody SpuTemplateReleaseDto spuTemplateReleaseDto) {
        boolean result = spuTemplateReleaseService.editSpuTemplateRelease(spuTemplateReleaseDto);
        return result ? Result.success("操作成功") : Result.error("操作失败");
    }


}
